package com.mall.controller;

import com.mall.domain.GoodsPics;
import com.mall.domain.ItemGoods;
import com.mall.domain.ListSeacher;
import com.mall.service.IGoodsDetailService;
import com.mall.service.IGoodsPicsService;
import com.mall.service.IItemGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("goods")
public class GoodsPicsController {
    @Autowired
    private IGoodsPicsService goodsPicsService;
    @Autowired
    private IGoodsDetailService goodsDetailService;

    @RequestMapping("/detail")
    public @ResponseBody
    Map<String,Object> findGoodsPics(HttpServletRequest request){
        Integer goods_id = Integer.parseInt(request.getParameter("goods_id"));

        Map<String, Object> map = new HashMap<>();
        Map<String,Object> msgMap = new HashMap<>();

        List<GoodsPics> goodsPics = goodsPicsService.findGoodsPics(goods_id);

        ItemGoods goodObj = goodsDetailService.findGoodsDetail(goods_id);

        msgMap.put("goods_id",goods_id);
        msgMap.put("cat_id",goodObj.getCat_id());
        msgMap.put("goods_name",goodObj.getGoods_name());
        msgMap.put("goods_price",goodObj.getGoods_price());
        msgMap.put("goods_introduce",goodObj.getGoods_introduce());
        msgMap.put("goods_small_logo",goodObj.getGoods_small_logo());
        msgMap.put("pics",goodsPics);

        Map<String,Object> metaMap = new HashMap<>();
        metaMap.put("code",200);
        metaMap.put("msg","查询成功");

        map.put("message",msgMap);
        map.put("meta",metaMap);
        return map;
    }
}

















